<template>

    <div>
        <!--        {{this.value}}-->
        <!--        父子组件通信，子组件里定义属性props ，属性类型定位object，
           props: {
                    parnentData: {
                        type: Object,
                        required: true
                    }
                }
                父亲组件里 调用子组件时将父亲的属性传递给子组件
                -->
        <div>test hello api</div>

        <simgle-item v-for="(item) in current"
                     :key="item.id"
                     :parnent-data="item"
        >
        </simgle-item>
        <p>子组件的选项是</p>
    </div>
</template>

<script>

    import SimgleItem from "@/components/SimgleItem2";

    export default {
        components: {SimgleItem},
        data: function () {
            return {
                list: [
                    [
                        {title: '测试单选A', value: "A", check: false, name: "ques1"},
                        {title: '测试单选B', value: "B", check: false, name: "ques1"},
                        {title: '测试单选C', value: "C", check: false, name: "ques1"},
                        {title: '测试单选D', value: "D", check: false, name: "ques1"}
                    ],
                    [
                        {title: '测试单选A2', value: "A", check: false, name: "ques1"},
                        {title: '测试单选B2', value: "B", check: false, name: "ques1"},
                        {title: '测试单选C2', value: "C", check: false, name: "ques1"},
                        {title: '测试单选D2', value: "D", check: false, name: "ques1"}
                    ]

                ],
                current: [], // 当前题目
                currentIndex: 0,
                value: '', // 临时储存子选项
                answers: [], // 存储子选项
                testHello: ''
            }
        }
        ,
        computed: {
            getValue() {
                return this.value;
            }
        }
        ,
        methods: {
            getSingleItemValue: function (data) {
                this.value = data;
                console.log("value = " + this.value)
                setTimeout(() => {
                    console.log("执行两秒")
                    this.getNext()
                    // this.message = '2秒已过';
                }, 2000);
            },
            getNext() {

                if (this.value === '') {
                    alert("没有正确选择选项")
                    return
                }
                this.answers.push(this.value)
                this.value = ''
                // 如果答题结束则修改题目
                if (this.currentIndex < this.list.length) {
                    this.current = this.list[this.currentIndex++]
                } else {
                    alert("已经答完题 答案是" + this.answers.join())
                }

            }
        },
        created() {
            console.log("created 加载")
            // console.log("this.list is"+this.list.forEach(t=>t.toString()))
            // 设为默认值
            this.current = this.list[this.currentIndex++]
            console.log("this.curent is" + this.current)
            console.log(this)
        }

    }

</script>